
package com.ztesoft.huangfu.learning.springboot.springbootrestful.service;


import static com.ztesoft.huangfu.learning.springboot.springbootrestful.entity.ProcessStatHolder.ERROR_CODE;
import static com.ztesoft.huangfu.learning.springboot.springbootrestful.entity.ProcessStatHolder.NOT_DEFINE_BUZ_EXCEPTION_CODE;
import static com.ztesoft.huangfu.learning.springboot.springbootrestful.entity.ProcessStatHolder.SUCCESS_CODE;

/**
 * Descrip:处理结果类，主要向前台返回后台相关的处理信息
 * @version 1.0
 * @since 2013-5-15 下午2:54:37
 *
 *
 * 新增状态码
 * update 2018/5/29 10:51 author: egan
 */
public class ProcessResult implements java.io.Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public final static String ERROR = ProcessStatHolder.RESULT_STAT_ERROR;


	public final static String SUCCESS = ProcessStatHolder.RESULT_STAT_SUCCESS;

	public final static String BUZ_EXCEPTION = ProcessStatHolder.RESULT_STAT_BUZ_EXCEPTION;



	public final static String SHOW_SQL = "SHOW_SQL";
	
	public final static String WARN = ProcessStatHolder.RESULT_STAT_WARN;
	
	/**
	 * 处理结果状态
	 */
	private String resultStat;


	/**
	 * 处理结果状态码
	 *  @author: egan
	 *  date 2018/5/29 10:51
	 */
	private int code = 0;

	/**
	 * 处理结果返回信息
	 */
	private String mess;
	
	/**
	 * 处理结果回调函数
	 */
	private String callBack;
	
	/**
	 *处理完成返回数据 
	 */
	private Object data;

	private String redirectURL;

	public ProcessResult() {
		this.resultStat = SUCCESS;
	}

	public ProcessResult(int code, String mess) {
		setCode(code);
		this.mess = mess;
	}
	@Deprecated
	public ProcessResult(String resultStat, String mess){
		this.resultStat = resultStat;

		this.mess = mess;
	}
	
	public ProcessResult(String resultStat){
		this.resultStat = resultStat;
	}
	@Deprecated
	public ProcessResult(String resultStat, String mess, Object data){
		this.resultStat = resultStat;
		setCode();
		this.mess = mess;
		this.data = data;
	}
	public ProcessResult(int code, String mess, Object data){
		this.code = code;
		this.mess = mess;
		this.data = data;
		setResultStat();
	}

	public String getResultStat() {
		return resultStat;
	}
	

	public void setResultStat(String resultStat) {
		this.resultStat = resultStat;
		setCode();
	}

	public void setResultStat() {
		if (code == 0){
			this.resultStat = (SUCCESS);
		}else if (code == 500 || code == ERROR_CODE){
			this.resultStat = (ERROR);
		}else {
			this.resultStat = (BUZ_EXCEPTION);
		}

	}

	public void setCode() {
		if (SUCCESS.equals(resultStat)){
			this.code =(SUCCESS_CODE);
		}else 	if (ERROR.equals(resultStat)){
			this.code =(ERROR_CODE);
		}else {
			this.code =(NOT_DEFINE_BUZ_EXCEPTION_CODE);
		}
	}

	public String getMess() {
		return mess;
	}

	public void setMess(String mess) {
		this.mess = mess;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
		setResultStat();
	}

	public String getCallBack() {
		return callBack;
	}

	public void setCallBack(String callBack) {
		this.callBack = callBack;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}


	public String getRedirectURL() {
		return redirectURL;
	}

	public void setRedirectURL(String redirectURL) {
		this.redirectURL = redirectURL;
	}
}

